package com.app.service.impl;

import com.app.entity.Orders;
import com.app.mapper.OrdersMapper;
import com.app.service.OrdersService;
import com.app.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lkg
 * @since 2021-04-14
 */
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {
    @Autowired
    private OrdersMapper ordersMapper;

    @Override
    public Result findOrdersAndProduct(String time) {
        return Result.success(ordersMapper.findOrdersAndProduct(time));
    }

    @Override
    public Result findOederNum() {
        QueryWrapper queryWrapper = new QueryWrapper();
        String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        queryWrapper.ge("ordertime", format);
        Integer total = ordersMapper.selectCount(queryWrapper);
        return Result.success(total);
    }

    @Override
    public Result editOrders(Orders orders) {
        ordersMapper.updateById(orders);
        return Result.success();
    }
}
